package com.tongji.diy.view.component3D
{
	import com.tongji.diy.view.component3D.ShapeToAdd;
	
	import flare.core.Mesh3D;
	import flare.materials.Material3D;
	import flare.materials.Shader3D;
	
	import flash.geom.Point;
	import flash.geom.Vector3D;
	
	public class ShapeToAddRect extends ShapeToAdd
	{
		public function ShapeToAddRect(roomShapePoints:Vector.<Point>, pos:Vector3D, roomBorder:RoomBorder, name:String = "")
		{
			super(roomShapePoints,pos,roomBorder);
			
			/*
				画墙
			*/
			
			//第一面墙
			borders.push(new Mesh3D());
			borders[0] = drawBorder(borders[0],_roomShapePoints[_roomShapePoints.length-1],_roomShapePoints[0],_roomShapePoints[1],_roomShapePoints[2]);
			//中间的墙
			borders.push(new Mesh3D());
			borders[1] = drawBorder(borders[1],_roomShapePoints[0],_roomShapePoints[1],_roomShapePoints[2],_roomShapePoints[3]);
			//最后面墙
			borders.push(new Mesh3D());
			borders[2] = drawBorder(borders[2],_roomShapePoints[1],_roomShapePoints[2],_roomShapePoints[3],_roomShapePoints[0]);
			
			/*
				调整位置
			*/
			
			this.refresh(pos,roomBorder);
		}
		
		override public function refresh(pos:Vector3D,roomBorder:RoomBorder):void
		{
			this._roomBorder = roomBorder;
			
			/*
			 *	rect没有重绘，所以要专门改所有surfaces[0]的材质
			 */
			
			var shader:Shader3D = roomBorder.surfaces[0].material.clone() as Shader3D;
			if(shader.filters.length > 1)
				shader.filters.pop();
			borders[0].surfaces[0].material = shader as Material3D;
			borders[1].surfaces[0].material = borders[0].surfaces[0].material;
			borders[2].surfaces[0].material = borders[0].surfaces[0].material;
			
			this.setPos(pos,roomBorder);
			this.setRot(roomBorder.getNormal());
		}
	}
}